from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager

db = SQLAlchemy()
login_manager = LoginManager()


def create_app():
    app = Flask(__name__)
    app.config.from_pyfile("app_cfg.py")
    db.init_app(app)
    login_manager.init_app(app)

    # 为了防止循环导入， 放在函数内部导入
    from app.main_bp import main_app
    app.register_blueprint(main_app, url_prefix='/chess')
    return app
